<template>
  <div class="app-main-content" style="height: 96%">
    <div style="display: flex; justify-content: space-between">
      <el-row>
        <el-button
          data-oauthUuid="1620625438000"
          type="primary"
          icon="el-icon-plus"
          @click="handlePrint"
        >
          打印
        </el-button>
      </el-row>
      <query-form
        class="query-form"
        :options="searchOptions"
        @query="onSearch"
      />
    </div>
    <scmsa-table
      ref="topTable"
      v-loading="tableLoading"
      :data="tableData"
      :column="tableColumn"
      align="center"
      border
      highlight-current-row
      pagination
      :current-page="currentPage"
      :page-size="pageSize"
      :total="totalPage"
      :row-key="(row) => row.id"
      @row-click="rowClickChange"
      @size-change="handlePageSizeChange"
      @pagination-current-change="handlePageCurrentChange"
      @selection-change="handleSelectionChange"
    />

    <update ref="add" />
  </div>
</template>

<script>
import update from './update'
export default {
  name: 'qualityDetection',
  data() {
    return {
      tableLoading: false,
      currentPage: 1,
      pageSize: 10,
      loading: false,
      delBtnLoading: false,
      selected: [],
      dialog: false,
      editIndex: 0,
      clickCode: null,
      actionForm: {
        code: '',
        VALUE_DESC: '',
      },
      searchOptions: [],
      queryForm: {
        value: null,
      },
      params: {
        page: 1,
        limit: 10,
      },
      tableData: [],
      totalPage: 0,
      queryChildForm: {},
    }
  },
  components:{
      update
  },
  computed: {
    tableTopHeight() {
      return (
        this.$store.state.settings &&
        this.$store.state.settings.tableHeight * 0.5 - 48
      )
    },
    isHaveCode() {
      return this.clickCode == null
    },
    tableColumn() {
      return [
        {
          type: 'selection',
          width: 55,
          align: 'center',
        },
        {
          prop: 'package',
          label: '编号',
          render: (h, params) => {
            return h(
              'span',
              {
                style: {
                  color: '#1890ff',
                  cursor: 'pointer',
                },
                on: {
                  click: (e) => {
                    this.openDetail(params.row)
                  },
                },
              },
              params.row.package
            )
          },
        },
        { prop: 'steel', label: '牌号' },
        { prop: 'batch', label: '批号', align: 'center' },
        {
          label: '规格(mm)',
          children: [
            { prop: 'outerDiamete', label: '外径' },
            { prop: 'wallThickness', label: '壁厚' },
          ],
        },
        {
          label: '数量',
          children: [
            { prop: 'count', label: '支数' },
            { prop: 'length', label: '长度' },
            { prop: 'weight', label: '重量' },
          ],
        },
        {
          label: '水压试验',
          children: [
            { prop: 'testPressure', label: '试验压力' },
            { prop: 'pressureHoldingTime', label: '稳压时间' },
            { prop: 'experimentalResults', label: '试验结果' },
          ],
        },
        {
          label: '无损试验',
          children: [
            { prop: 'vortexLeaned', label: '涡探' },
            { prop: 'superAgent', label: '超探' },
          ],
        },
        {
          label: '冲击试验',
          children: [
            { prop: 'specimenSize ', label: '试样尺寸E3' },
            { prop: 'testTemperature', label: '试验温度（℃）' },
          ],
        },
        { prop: 'sampleNumber', label: '试样号' },
        {
          label: '交货状态',
          children: [
            { prop: 'ts', label: '抗拉强度T.S' },
            { prop: 'ys', label: '屈服强度Y.S' },
            { prop: 'el', label: '延伸率EL' },
            { prop: 'z', label: '收缩Z(%)' },
          ],
        },
        {
          label: '交货状态高温拉伸300℃',
          children: [
            { prop: 'ts', label: '抗拉强度T.S' },
            { prop: 'ys', label: '屈服强度Y.S' },
            { prop: 'el', label: '延伸率EL' },
            { prop: 'z', label: '收缩Z(%)' },
          ],
        },
        { prop: 'spinOver', label: '扩口' },
        { prop: 'flaser', label: '压扁' },
        { prop: 'curve', label: '弯曲' },
        {
          label: '硬度',
          children: [
            { prop: 'bh', label: '布氏' },
            { prop: 'hrc', label: '洛氏' },
          ],
        },
        { prop: 'grainSize', label: '晶粒度' },
        { prop: 'microstructural', label: '显微组织' },
        {
          label: '非金属夹杂物 E8',
          children: [
            { prop: 'niA', label: 'A 粗/细' },
            { prop: 'niB', label: 'B 粗/细' },
            { prop: 'niC', label: 'C 粗/细' },
            { prop: 'niD', label: 'D 粗/细' },
            { prop: 'niDs', label: 'DS' },
          ],
        },
        {
          label: '低倍检验E15',
          children: [
            { prop: 'me1', label: '1' },
            { prop: 'me2', label: '2' },
            { prop: 'me3', label: '3' },
            { prop: 'me4', label: '4' },
            { prop: 'me5', label: '5' },
            { prop: 'me6', label: '6' },
          ],
        },
        { prop: 'heatNo', label: '熔炼号' },
        {
          label: '化学成分（%）',
          children: [
            //C	S	Mn	Si	P 	Cr	Ni	Cu	Mo	V	Ti	Al	Nb	W	N	B	As	Sn	Zr	Pb	Bi	Sb				Cr+Cu+Mo+Ni				Cu+6Sn	Al+Ti/2		Ceq
            { prop: 'C', label: 'C', width: 50, align: 'center' },
            { prop: 'S', label: 'S', width: 50, align: 'center' },
            { prop: 'Si', label: 'Si', width: 50, align: 'center' },
            { prop: 'P', label: 'P', width: 50, align: 'center' },
            { prop: 'Cr', label: 'Cr', width: 50, align: 'center' },
            { prop: 'Ni', label: 'Ni', width: 50, align: 'center' },
            { prop: 'Cu', label: 'Cu', width: 50, align: 'center' },
            { prop: 'Mo', label: 'Mo', width: 50, align: 'center' },
            { prop: 'V', label: 'V', width: 50, align: 'center' },
            { prop: 'Ti', label: 'Ti', width: 50, align: 'center' },
            { prop: 'Al', label: 'Al', width: 50, align: 'center' },
            { prop: 'Nb', label: 'Nb', width: 50, align: 'center' },
            { prop: 'W', label: 'W', width: 50, align: 'center' },
            { prop: 'N', label: 'N', width: 50, align: 'center' },
            { prop: 'B', label: 'B', width: 50, align: 'center' },
            { prop: 'As', label: 'As', width: 50, align: 'center' },
            { prop: 'Sn', label: 'Sn', width: 50, align: 'center' },
            { prop: 'Zr', label: 'Zr', width: 50, align: 'center' },
            { prop: 'Pb', label: 'Pb', width: 50, align: 'center' },
            { prop: 'Bi', label: 'Bi', width: 50, align: 'center' },
            { prop: 'Sb', label: 'Sb', width: 50, align: 'center' },
            { prop: 'ccmn', label: 'Cr+Cu+Mo+Ni', align: 'center' },
            { prop: 'c6', label: 'Cu+6Sn', align: 'center' },
            { prop: 'at', label: 'Al+Ti/2', align: 'center' },
            { prop: 'ceq', label: 'Ceq', align: 'center' },
          ],
        },
      ]
    },
  },
  mounted() {
    this.fetchTableData()
  },
  methods: {
    rowClickChange(row, column, cell, event) {
      console.log(row)
    },
    fetchTableData() {
      this.tableLoading = true
      let _self = this
      //模拟加载数据
      setTimeout(() => {
        _self.tableData = [
          {
            package: 10000,
            steel: 10000,
            batch: 1,
            outerDiamete: '10',
            wallThickness: '5',
            count: 15,
            length: 170,
            weight: '50',
            testPressure: 'xx',
            pressureHoldingTime: 'pressureHoldingTime',
            experimentalResults: 'experimentalResults',
            vortexLeaned: 'vortexLeaned',
            superAgent: 'superAgent',
            specimenSize: 'specimenSize',
            testTemperature: '36.5',
            sampleNumber: 200,
            ts: '15',
            ys: '16',
            el: '17',
            z: '18',
            spinOver: 'spinOver',
            flaser: 'flaser',
            curve: 'curve',
            bh: 'bh',
            hrc: 'hrc',
            grainSize: 'grainSize',
            microstructural: 'microstructural',
            niA: 'niA',
            niB: 'niB',
            niC: 'niC',
            niD: 'niD',
            niDs: 'niDs',
            me1: 'me1',
            me2: 'me2',
            me3: 'me3',
            me4: 'me4',
            me5: 'me5',
            me6: 'me6',
            heatNo: 10001,
            C: '',
            S: '',
            Si: '',
            P: '',
            Cr: '',
            Ni: '',
            Cu: '',
            Mo: '',
            V: '',
            Ti: '',
            Al: '',
            Nb: '',
            W: '',
            N: '',
            B: '',
            As: '',
            Sn: '',
            Zr: '',
            Pb: '',
            Bi: '',
            Sb: '',
            ccmn: '',
            c6: '',
            at: '',
            ceq: '',
          },
        ]
        _self.totalPage = _self.tableData.length
        _self.tableLoading = false
      }, 1500)
    },
    openDetail(data) {
      this.$refs.add.show({
        type: 'add',
        data: data,
        title: '检验结果录入',
      })
    },
    // 每页条数发生改变时返回值
    handlePageSizeChange(v) {
      this.pageSize = v
      //   this.fetchTableData()
    },
    // 当前选中页发生改变时返回值
    handlePageCurrentChange(v) {
      this.currentPage = v
      //   this.fetchTableData()
    },
    // checkbox 当选择项发生变化时会触发该事件
    handleSelectionChange(v) {
      this.selected = v
    },
    // 重置form
    resetFieldsForm(formName) {
      this.$refs[formName].resetFields()
      this.actionForm = {}
    },
    // 查询重置
    onReset(formName) {
      this.$refs[formName].resetFields()
      this.currentPage = 1
      this.fetchTableData()
    },
    // 查询搜索
    onSearch() {
      this.fetchTableData()
    },
    // 点击打印
    handlePrint() {
      console.log('打印')
    },
  },
}
</script>

<style scoped>
.valueSetCodeA {
  color: blue;
}
</style>
